package
{
	import flash.events.Event;
	import flash.net.SharedObject;
	
	import modules.entity.LanguageType;


	public class GlobalData
	{
		public static const rootPath:String = "http://localhost:8080/newmajiang/";

		public static const configPath:String = rootPath + "config.xml";
		
		/**
		 * 版本号
		 **/
		public static const VERSION:String = "2013.4.26 14:38";
		
		public static var logFunc:Function;

		/** 登陆服务器列表 */
		public static var loginServerArray:Array = [];
		
		/** 默认策略端口 */
		public static var policy:uint;
		
		public static var httpServerHost:String;
		
		/**
		 * config数据
		 */
		public static var vppConfigData:Array = [];
		
		/** 大厅服务器列表 */
		public static var lobbyServerArray:Array;
		
		/** 平台用户id */
		public static var userid:String = "727";
		
		/** 用户名 */
		[Bindable]
		public static var username:String = "";
		
		/** 玩家昵称 */
		[Bindable]
		public static var nickname:String = "";
		
		/** 玩家性别 */
		[Bindable]
		public static var sex:uint = 0;
		
		/** 用户余额 */
		[Bindable]
		public static var balance:Number = 0;
		
		/** 玩家币种 */
		[Bindable]
		public static var myCurrency:String = "";
		
		
		/**
		 * 更新用户余额时间（为了得到最后的数据）
		 */
		public static var updateBalanceTime:uint = 0;
		
		/** 用户头像 */
		public static var avatarId:int = 2;
		
		[Bindable]
		public static var myVPPLevel:int = 0;
		
		/** 是否是回放模式 */
		[Bindable]
		public static var isReplaying:Boolean = false; 
		
		/** 经验值 */
		[Bindable]
		public static var _myVPP:Number = 0;
		
		public static function get myVPP():Number
		{
			return _myVPP;
		}
		
		public static function set myVPP(vpp:Number):void
		{
			_myVPP = vpp;
			currentMinVPP = 0;
			currentMaxVPP = vppConfigData[0];
			for (var i:int = 0; i < vppConfigData.length; i++)
			{
				if (vpp <= vppConfigData[i])
				{
					if (i > 0)
					{
						currentMinVPP = vppConfigData[i - 1];
					}
					currentMaxVPP = vppConfigData[i];
					break;
				}
			}
			if (vpp > vppConfigData[vppConfigData.length - 1])
			{
				currentMinVPP = vppConfigData[vppConfigData.length - 1];
				currentMaxVPP = vpp;
			}
			myVPPLevel = getVPPLevel(vpp);
		}
		
		public static function getVPPLevel(vpp:Number):int
		{
			var vppLevel:int = 0;
			for (var i:int = 0; i < vppConfigData.length; i++)
			{
				if (vpp >= vppConfigData[i])
				{
					vppLevel = i + 1;
				}
			}
			return vppLevel;
		}
		
		[Bindable]
		public static var currentMaxVPP:Number = 0;
		
		[Bindable]
		public static var currentMinVPP:Number = 0;
		
		public static function get avatarStr():String
		{
			return "" + ["male", "female"][sex] + avatarId;
		}
		
		/** 在线玩家数 */
		[Bindable]
		public static var online:int = 100;
		
		/** 在座玩家数 */
		[Bindable]
		public static var sitNum:int = 100;
		
		[Bindable]
		public static var gameFontWeight:String = "normal";
		
		/**
		 * 语言类型
		 **/
		public static var language:String = LanguageType.chineseTc;
		
		/**
		 * 本局游戏结束后清空桌面时间
		 **/
		public static var gameOverClearTime:int = 10;
		
		/**
		 * 更新时服务器时间
		 **/
		private static var preServerTime:Date = new Date();
		
		/**
		 * 当前服务器时间
		 **/
		public static var currentServerTime:Date = new Date();
		
		/**
		 * 更新本机时间
		 **/
		private static var updateTime:Date = new Date();
		
		public static function set serverTime(value:int):void
		{
			preServerTime.time = value * 1000;
			updateTime = new Date();
		}
		
		/**
		 * 服务器时间
		 **/
		[Bindable]
		public static var serverTimeStr:String = "";
		
		private static var preTime:Number = 0;
		
		public static function onEnterFrame(event:Event):void
		{
			var currentTime:Date = new Date();
			//每秒刷新大厅时间
			if (currentTime.time > preTime + 1000)
			{
				currentServerTime.time = preServerTime.time + (currentTime.time - updateTime.time);
				
				serverTimeStr = (currentServerTime.date < 10 ? "0" + currentServerTime.date : currentServerTime.date) + "-" + (currentServerTime.month + 1 < 10 ? "0" + (currentServerTime.month + 1) : (currentServerTime.month + 1)) + "-" + currentServerTime.fullYear + " " + currentServerTime.toTimeString().split(" ")[0] + "(GMT+8)";
				preTime = currentTime.time;
			}
		}
		
		/**
		 * 获取本地数据
		 */
		public static function getLSO():Object
		{
			return SharedObject.getLocal("majiang");
		}
	}
}
